#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define flr(x,l,r) for (int x = l; x <= r; ++ x)
#define frl(x,r,l) for (int x = r; x >= l; -- x)
#define szf sizeof
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define pn printf("\n")
#define vc vector 
#define pb push_back
#define sz size

using namespace std;

const int N = 15;

int l, r, p;
int f[N][10][110];

int mod(int x, int y) {
    return (x % y + y) % y;
}

void init() {
    memset(f, 0, szf f);
    flr (j, 0, 9) f[1][j][j % p] ++ ;
    
    flr (i, 2, N - 1)
        flr (j, 0, 9)
            flr (k, 0, p - 1)
                flr (x, 0, 9)
                    f[i][j][k] += f[i - 1][x][mod(k - j, p)];
}

int dp(int n) {
    if (!n) return 1;
    
    vc<int> nums;
    while (n) nums.pb(n % 10), n /= 10;
    
    int res = 0, last = 0;
    frl (i, nums.sz() - 1, 0) {
        int x = nums[i];
        
        flr (j, 0, x - 1) 
            res += f[i + 1][j][mod(-last, p)];
            
        last += x;
        
        if (!i && last % p == 0) res ++ ;
    }
    
    return res;
}

int main() {
	while (cin >> l >> r >> p) init(), out(dp(r) - dp(l - 1)), pn;
	
	return 0;
}